package design.graduation.crawler.task;

import design.graduation.crawler.service.CrawlerBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * @author: 洪少尉
 * @Date: 2020/3/29 13:22
 * @Description:
 */
@Component
public class SpringDataPipeline implements Pipeline {
	@Autowired
	private CrawlerBookService crawlerBookService;
	@Override
	public void process(ResultItems resultItems, Task task) {
		if(resultItems.get("books") != null){
			crawlerBookService.saveAll(resultItems.get("books"));
			return;
		}
		if (resultItems.get("book_download") !=null){
			crawlerBookService.updateUrl(resultItems.get("book_download"));
		}
	}
}
